package com.ruoyi.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.course.domain.TVideo;
import com.ruoyi.course.domain.TVideoCategory;
import com.ruoyi.course.mapper.TVideoCategoryMapper;
import com.ruoyi.course.vo.TVideoVo;
import com.ruoyi.course.mapper.TVideoMapper;
import com.ruoyi.course.service.ITVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 视频Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-07
 */
@Service
public class TVideoServiceImpl extends ServiceImpl<TVideoMapper, TVideo> implements ITVideoService {

    @Override
    public TableDataInfo<TVideoVo> queryList(TVideoVo entity) {
        return PageUtils.buildDataInfo(this.baseMapper.queryList(PageUtils.buildPage(), entity));
    }

    @Override
    public List<TVideoVo> queryAll(TVideoVo entity) {
        return this.baseMapper.queryList(entity);
    }

    @Override
    public TVideoVo queryById(Long id) {
        return this.baseMapper.queryById(id);
    }

    @Override
    public List<Long> queryVideoIdsByCategoryIds(List<Long> categoryIds) {
        QueryWrapper<TVideo> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id").in("category_id", categoryIds);
        List<TVideo> videos = this.baseMapper.selectList(queryWrapper);

        // 提取视频ID列表
        return videos.stream()
                .map(TVideo::getId)
                .collect(Collectors.toList());
    }


}
